<!DOCTYPE html>
<html lang="en-us" id="extr-page">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" media="screen" href="../../global/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../global/layui/css/layui.css">
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
    <form class="form-horizontal" onsubmit="return false" id="form" enctype="multipart/form-data">
        <fieldset>
     <input type="hidden" id="id" name="id" />
          <div class="form-group">
           <label class="col-md-2 control-label">名称</label>
           <div class="col-md-10">
            <input class="form-control" placeholder="名称" type="text" name="title" id="title" data-bv-notempty="true" data-bv-notempty-message="名称不能为空" />
           </div>
          
          </div>
         <!--  <div class="form-group">
           <label class="col-md-2 control-label">内容</label>
           <div class="col-md-10">
            <input class="form-control" placeholder="内容" type="text" name="content" id="content" data-bv-notempty="true" data-bv-notempty-message="内容不能为空" />
           </div>
          </div> -->
           <div class="form-group" >
                <label class="col-md-2 control-label">内容</label>
                <!-- 加载编辑器的容器 -->
                <div class="col-md-10">
                    <textarea id="content" name="content" ></textarea>
                </div>
      </div>
      <div class="form-group">
                               <label class="col-md-2 control-label">图片:</label>
                               <div class="col-md-10">
                               <img id="icon" />
                               <input type="file" name="icon" id="icon" />
                               </div>
                               </div>
          <div class="form-group">
                <label class="col-md-2 control-label">标识</label>
                <div class="col-md-10" style="width: 120px">
                 <select class="form-control input-sm" name="flag" id="flag">
                 <option value="0">首页头条</option>
                 <option value="1" selected="selected">附近公告</option> </select>
            </div>
            </div>
            <div class="form-actions">
                <div class="row" align="center">
                    <div class="col-md-12">
                        <button class="btn btn-primary" onclick="location.href='headList.html'">返回</button>
                        <button class="btn btn-primary" type="submit" onclick="update()">
                            <i class="fa fa-save"></i> 保存
                        </button>
                    </div>
                </div>
            </div>

        </fieldset>
    </form>
</div>
<script type="text/javascript" src="../../global/js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../global/js/jq.js"></script>
<script type="text/javascript" src="../../global/js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="../../global/js/common.js"></script>
<script type="text/javascript" src="../../global/layui/layui.js"></script>
<script type="text/javascript" src="../../global/js/ajaxfileupload.js"></script>
<script type="text/javascript">
//富文本编辑


</script>
<script type="text/javascript">
var layedit;
var index
layui.use(['layer', 'layedit'], function () {
  var layer = layui.layer;
  layedit = layui.layedit;
  layedit.set({
      uploadImage: {
          url: '../../clyjHeadlines/uploadFile' ,//接口url
          type: 'post' //默认post
      }
  });
	index = layedit.build('content'); //建立编辑器
});

    layui.use(['layer', 'laydate'], function () {
        var layer = layui.layer;
        var laydate = layui.laydate;
        laydate.render({
            elem: '#birthday'
        });
    });

    initData();
    function initData() {
        var id = getUrlParam("id");
        if (id != "") {
            $.ajax({
                type: 'get',
                url: "/clyjHeadlines/" + id,
                async: false,
                success: function (result) {
                     var data = result.data;
                     $("#id").val(data.id);
                     $("#title").val(data.title);
                     $("#content").val(data.content);
                     $("#flag").val(data.flag);
                     $("#icon").attr("src",data.pics);
                }
            })
        }
    }
    $('#form').bootstrapValidator();

    function update() {
        // 表单验证
        var bootstrapValidator = $("#form").data('bootstrapValidator');
        bootstrapValidator.validate();
        if (!bootstrapValidator.isValid()) {
            return;
        }
        layedit.sync(index);
        var formdata = $("#form").serializeObject(  );

            $("form").ajaxSubmit({
            type: 'post',
            url: '/clyjHeadlines/updateHeadline',
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(formdata),
            success: function (data) {
                layer.msg("修改成功", {shift: -1, time: 1000}, function () {
                    location.href = "headList.html";
                });
            }
        });
    }
</script>
</body>
</html>